package com.shuqi.model.parse.parser;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.shuqi.common.utils.Log4an;
import com.shuqi.common.utils.Util;
import com.shuqi.model.bean.BuyRecordInfo;
import com.shuqi.model.bean.BuyRecordsInfo;
import com.shuqi.model.parse.HandlerBase;

/**
 * 购买历史解析
 * 
 * @author zhuchen
 * 
 */
public class PurchaseHistoryParser extends HandlerBase {

    private BuyRecordsInfo buyRecordsInfo;
    private BuyRecordInfo buyRecordInfo;
    private List<BuyRecordInfo> list;


    @Override
    public Object getParsedData() {
        // TODO Auto-generated method stub
        return buyRecordsInfo;
    }



    @Override
    public void startDocument() throws SAXException {
        // TODO Auto-generated method stub
        list = new ArrayList<BuyRecordInfo>();
        super.startDocument();
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attributes)
            throws SAXException {

        if ("BuyRecords".equals(localName)) {
            buyRecordsInfo = new BuyRecordsInfo();
            buyRecordsInfo.setPageIndex(isNull(attributes, "pageIndex"));
            buyRecordsInfo.setTotalPage(isNull(attributes, "totalPage"));
        } else if ("BuyRecord".equals(localName)) {
            buyRecordInfo = new BuyRecordInfo();
            try {
                String time = isNull(attributes, "time");
                buyRecordInfo.setTime(Util.getStrTime(time));
            } catch (Exception e) {
            }
            buyRecordInfo.setBookName(isNull(attributes, "bookName"));
            buyRecordInfo.setInfo(isNull(attributes, "info"));// 购买类型
            buyRecordInfo.setImgUrl(isNull(attributes, "imgUrl"));
            buyRecordInfo.setAnthor(isNull(attributes, "anthor"));
            buyRecordInfo.setBookId(isNull(attributes, "bookId"));
            buyRecordInfo.setType(isNull(attributes, "type"));
            buyRecordInfo.setChapterTotal(isNull(attributes, "chapterTotal"));
            buyRecordInfo.setHide(isNull(attributes, "hide"));
            buyRecordInfo.setCr_cover_isopen(isNull(attributes, "cr_cover_isopen"));
            list.add(buyRecordInfo);
            buyRecordsInfo.setList(list);
        }

    }

    @Override
    public void endDocument() throws SAXException {
        // TODO Auto-generated method stub
        super.endDocument();
    }

}
